#!/usr/bin/env python
# -*- coding=utf-8 -*-
 
# @File    :   app.py
# @Version :   1.0
# @Author  :   xin
# @Time    :   2023/12/11 09:30:06
#Description:

from flask import Flask
import threading
import rospy
import gevent
import random
import time

random_int = random.randint(0, 100)
__node_name = "app3_{}".format(random_int)
rospy.init_node(__node_name)
app =Flask(__name__)


def start_register_blueprint():
    from blueprint.blueprint_account import account_parser,account_server
    from blueprint.blueprint_map import map_parser,map_server
    from blueprint.blueprint_task import task_parser,task_server
    from blueprint.blueprint_robot import robot_parser,robot_server
    from blueprint.blueprint_cmdvel import cmdvel_parser,cmdvel_server
    from blueprint.blueprint_bulkdata import bulkdata_parser,bulkdata_server
    from blueprint.blueprint_hardware import hardware_parser,hardware_server
    from blueprint.blueprint_navgation import navgation_parser,navgation_server
    from blueprint.blueprint_opencv import opencv_server
    blueprint = []
    
    account_parser.InitParser(__node_name)
    blueprint.append(account_server)

    map_parser.InitParser(__node_name)
    blueprint.append(map_server)

    task_parser.InitParser(__node_name)
    blueprint.append(task_server)

    robot_parser.InitParser(__node_name)
    blueprint.append(robot_server)

    cmdvel_parser.InitParser(__node_name)
    blueprint.append(cmdvel_server)

    bulkdata_parser.InitParser(__node_name)
    blueprint.append(bulkdata_server)

    hardware_parser.InitParser(__node_name)
    blueprint.append(hardware_server)

    navgation_parser.InitParser(__node_name)
    blueprint.append(navgation_server)

    blueprint.append(opencv_server)

    '''
    注册蓝图
    '''
    for blueprint in blueprint:
        app.register_blueprint(blueprint)
        print("[{}]Register flask blueprint: {}".format(__node_name, blueprint.name))
        
start_register_blueprint()

def start1():
     app.run(host="0.0.0.0",port=5000)
     
def start2():
    from gevent import pywsgi
    server_=pywsgi.WSGIServer(("0.0.0.0", 5000), app)
    server_.serve_forever()

if __name__ == "__main__":
    start2()
    pass